<?php

/*
Edit Trivia Question (admin_edit_trivia_q.pro.php)
*/

$page_title = "Edit Trivia Question";
$rank_check = 7;
include "../global.inc.php";

if ((!$edit_question) or (!$answer1) or (!$answer2) or (!$answer) or (!$trivia_game))
{
	die(header(error("admin_edit_trivia_question.php?game=$game&question=$edit_id","Please fill out the form completely. Remember, you need at least two answers.")));
}

$find_game = fetch("SELECT id FROM trivia_games WHERE id = '$trivia_game' AND game = '$game'");

if (!$find_game[id])
{
	die(header(error("admin_edit_trivia_question.php?game=$game&question=$edit_id","This game does not exist.")));
}

if ((($answer == 1) and (!$answer1)) or (($answer == 2) and (!$answer2)) or (($answer == 3) and (!$answer3)) or (($answer == 4) and (!$answer4)))
{
	die(header(error("admin_edit_trivia_question.php?game=$game&question=$edit_id","Make sure the answer you checked is a real answer.")));
}

if (($answer < 1) or ($answer > 4))
{
	die(header(error("admin_edit_trivia_question.php?game=$game&trivia=$trivia_game","Don't cheat.")));
}

$edit_question = strip_tags($edit_question,"<font><b><i><u>");
$answer1 = strip_tags($answer1,"<font><b><i><u>");
$answer2 = strip_tags($answer2,"<font><b><i><u>");
$answer3 = strip_tags($answer3,"<font><b><i><u>");
$answer4 = strip_tags($answer4,"<font><b><i><u>");

mysql_query("UPDATE trivia_questions SET trivia_game = '$trivia_game' WHERE id = '$edit_id'");
mysql_query("UPDATE trivia_questions SET question = '$edit_question' WHERE id = '$edit_id'");
mysql_query("UPDATE trivia_questions SET answer1 = '$answer1' WHERE id = '$edit_id'");
mysql_query("UPDATE trivia_questions SET answer2 = '$answer2' WHERE id = '$edit_id'");
mysql_query("UPDATE trivia_questions SET answer3 = '$answer3' WHERE id = '$edit_id'");
mysql_query("UPDATE trivia_questions SET answer4 = '$answer4' WHERE id = '$edit_id'");
mysql_query("UPDATE trivia_questions SET answer = '$answer' WHERE id = '$edit_id'");

header(error("admin_edit_trivia_question.php?game=$game&question=$edit_id","Question successfully added."));

?>
